package controller;

import java.io.IOException;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import dao.LeaveDao;
/**
 * Servlet implementation class checkServlet
 */
@WebServlet("/UpdateLeaveServlet")
public class UpdateLeaveServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public UpdateLeaveServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("UTF-8");
		boolean b = false; // 初始化返回值为 false
		String number = request.getParameter("number");
		String status = request.getParameter("status");
		String refuse = request.getParameter("refuse");
		
		// 设置响应内容类型
        response.setContentType("text/html;charset=UTF-8");
		LeaveDao dao = new LeaveDao();
			
		
		//将数据写入数据库
		b=dao.updateleave(number,status, refuse);
				
		//修改成功，弹出成功提示框
		if(b==true) {						
			// 跳转回原页面
			response.sendRedirect("View_leave/T_leave.jsp");
	        
		}else {
			System.out.print("请假清单修改失败 ");
		}
			
		
	}

}
